'use strict';

const BaseService = require('./base');
const modelName = 'Category';

class SchoolService extends BaseService {
  constructor(ctx) {
    super(ctx, modelName);
  }
  getListOrder() {
    return [
      [
        'sort',
        'ASC'
      ]
    ]
  }
  getPageOrder() {
    return [
      [
        'sort',
        'ASC'
      ]
    ]
  }

  async deleteById(id) {
    // 删除所有商品
    const list = await this.ctx.service.product.allList({
      category_id: id
    })
    for (let i = 0, l = list.length; i < l; i++) {
      await this.ctx.service.product.deleteById(list[i].id)
    }
    return super.deleteById(id);
  }
}

module.exports = SchoolService;
